<template>
	<div>
		
		<div align="left">
			<el-button type="primary" @click="query">新增入库订单</el-button>
			<!-- :visible.sync="dialogFormVisible" -->
			<el-dialog title="入库操作" :visible.sync="dialogFormVisible">
				<el-form :model="form">
					<el-form-item label="入库人姓名:" :label-width="formLabelWidth">
						<el-select v-model="userdata.usname" placeholder="请选择姓名">
							<el-option v-model="user.usname" v-for="user in userdata" :key="user.usid" @click="options(usname)">{{user.usname}}</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="身份证号" :label-width="formLabelWidth">
						<el-input v-model="form.inidcard" autocomplete="off"></el-input>
					</el-form-item>
					<el-form-item label="联系电话" :label-width="formLabelWidth">
						<el-input v-model="form.usphone" autocomplete="off"></el-input>
					</el-form-item>
					<el-form-item label="入库商品" :label-width="formLabelWidth">
						<el-select v-model="shopdata.shopname" placeholder="请选择商品">
							<el-option v-model="shop.shopname" v-for="shop in shopdata" :key="shop.shopid">{{shop.shopname}}</el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="入库数量" :label-width="formLabelWidth">
						<el-input v-model="form.innum" autocomplete="off"></el-input>
					</el-form-item>
				</el-form>
				<div slot="footer" class="dialog-footer">
					<el-button @click="dialogFormVisible = false">取 消</el-button>
					<el-button type="primary" @click="inshop">确 定</el-button>
				</div>
			</el-dialog>

		</div>
		<hr>
		<div align="center">
			<ul style="list-style: none; padding-left: initial; width: 100%;" >
				<li class="inshop" style="border-bottom: 20px solid #E9EEF3; " v-for="inshop in inshopdata"  :key="inshop.inid" >
					<el-descriptions style="width: 80%;box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1)  " align="center" >
						<el-descriptions-item label="入库人姓名">{{inshop.user.usname}}</el-descriptions-item>
						<el-descriptions-item label="身份证号">{{inshop.inidcard}}</el-descriptions-item>
						<el-descriptions-item label="入库时间">{{inshop.inaddtime}}</el-descriptions-item>
						<el-descriptions-item label="入库商品">{{inshop.shop.shopname}}</el-descriptions-item>
						<el-descriptions-item label="入库数量">{{inshop.innum}}</el-descriptions-item>
						<el-descriptions-item label="操作人" v-for="loginname in loginname" :key="loginname.usname">{{loginname.usname}}</el-descriptions-item>
					</el-descriptions>
				</li>
			</ul>
		</div>
		 <div align="center" style="margin-top: 30px;">
		   <el-pagination background layout="prev, pager, next" :total="paging.count" :current-page.sync="paging.page"
		   :pager-count='5' :page-count="paging.pagemax"  :page-size="paging.pagesize" @current-change="accountAll()"
		   >
		   </el-pagination>
		  </div>
	</div>
</template>

<script>
	let _this;
	export default {
		created() {
			_this = this
			//_this.inshopshow()
			_this.login()
			_this.accountAll()
		},
		data() {
			return {
				dialogTableVisible: false,
				dialogFormVisible: false,
				form: {

					inidcard: '',
					usphone: '',
					innum: '',
					delivery: false,
					type: [],
				},
				formLabelWidth: '120px',
				/* 以下全是分页 */
				 paging:{
				   page: 1,
				   pagesize:5,
				   count:0,
				   pagemax:0
				 },	
				shopdata: [],
				userdata: [],
				inshopdata: [],
				zhi:'',
				idmes:'',
				phone:'',
				loginid:localStorage.getItem("usid"),
				loginname:[],
				accountdata:[]
			}
		},
		methods: {
			
				
			query() {
				_this.dialogFormVisible = true,
					_this.$axios.post(
						"/inshop/list")
					.then(function(param) {
						console.log(param)
						_this.shopdata = param.data.shops
						_this.userdata = param.data.users
					})
			},
			login(){
				_this.$axios.post(
					"/inshop/user",
					{
						"usid":_this.loginid
					})
				.then(function(param) {
					console.log("用户信息：")
					console.log(_this.loginid)
					console.log(param)
					_this.loginname = param.data
					
				})
			},
			
			inshop() {
				_this.dialogFormVisible = false,
					// alert(_this.userdata.usname+_this.form.inidcard+_this.form.usphone+_this.shopdata.shopname+_this.form.innum)
					_this.$axios.post(
						"/inshop/add", {
							"usname": _this.userdata.usname,
							"inidcard": _this.form.inidcard,
							"usphone": _this.form.usphone,
							"shopname": _this.shopdata.shopname,
							"innum": _this.form.innum
						}
					)
					.then(function(param) {
						console.log(param)
						_this.accountAll()

					})
					.catch(function(err) {
						console.log(err)
					})
			},
			accountAll() {
			  _this.$axios.post(
			      "/inshop/accountAll",
			      {
			        page:_this.paging.page,
			        pagesize: _this.paging.pagesize
			      }
			    )
			    .then(function(accountdata) {
					console.log("分页数据：")
			      console.log(accountdata.data)
			      //_this.accountdata = _this.inshopdata
				  _this.inshopdata=accountdata.data.inshops
			      _this.paging = accountdata.data.pages
			    })
			    .catch(function(err) {
			      console.log(err)
			    })
			},
		} 
	}
</script>

<style>

</style>
